package com.sise.Array;

import java.util.HashMap;
import java.util.Map;

/**
 *      1. 两数之和
 */
public class _01_twoSum {
    public int[] twoSum(int[] nums, int target) {
        int[] res = new int[2];
        Map<Integer,Integer> map = new HashMap();
        for (int i = 0; i < nums.length; i++){
            int now = target - nums[i];
            if (map.containsKey(now)){
                res[0] = map.get(now);
                res[1] = i;
                return res;
            }else {
                map.put(nums[i], i);
            }
        }
        return res;
    }
}
